﻿using System.Collections.Generic;

namespace Basmus.Web.Topology
{
    internal class Domain : IDomain
    {
        public ITopology Topology { get; private set; }

        public string DomainName { get; private set; }

        public Domain(ITopology topology, string domain)
        {
            Topology = topology;
            DomainName = domain;
        }

        private readonly object _lock = new object();

        private readonly List<IApplication> _appDeclarations = new List<IApplication>();

        public IEnumerable<IApplication> AppDeclarations()
        {
            return _appDeclarations;
        }

        public void Add(IApplication application)
        {
            lock (_lock)
            {
                if (!_appDeclarations.Contains(application))
                {
                    _appDeclarations.Add(application);
                }
            }
        }

        public void Remove(IApplication application)
        {
            lock (_lock)
            {
                if (_appDeclarations.Contains(application))
                {
                    _appDeclarations.Remove(application);
                }
            }
        }
    }
}